-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PWA option to ensure cross-origin isolation headers on web export #86089
Conversation
cd0c35e
to
ba6cb81
Compare
This comment was marked as outdated.
This comment was marked as outdated.
830601c
to
ad8b31d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this 💙 .
It's looking good overall 🚀 (see my comment on moving some code into engine.js
).
I like the s/@/__
rename, I wish it was done in its own PR though (EDIT: We can probably refactor this further into something similar to GODOT_CONFIG
in a separate PR).
There are some "style" changes (e.g. using the loose equality operator) which are not great in JS .
I'll look into normalizing the service worker using eslint like we do for other bits of the javascript.
if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) { | ||
// There's a chance that installing the service worker would fix the issue | ||
Promise.race([ | ||
navigator.serviceWorker.getRegistration().then((registration) => { | ||
if (registration != null) { | ||
return Promise.reject(new Error('Service worker already exists.')); | ||
} | ||
return registration; | ||
}).then(() => engine.installServiceWorker()), | ||
// For some reason, `getRegistration()` can stall | ||
new Promise((resolve) => { | ||
setTimeout(() => resolve(), 2000); | ||
}), | ||
]).catch((err) => { | ||
console.error('Error while registering service worker:', err); | ||
}).then(() => { | ||
window.location.reload(); | ||
}); | ||
} else { | ||
// Display the message as usual | ||
const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n'; | ||
displayFailureNotice(missingMsg + missing.join('\n')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this to a function of platform/js/engine/engine.js
like we did for Engine.getMissingFeatures
.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep the code as is, finally. We would need to pass in parameters to that function the config and the engine
variable, which seems a little bit excessive.
Attached the 2 patches (001 adds the service worker linting and its config, 002 is just a linter pass). EDIT: Remember to |
Actually, this was done precisely with that in mind. You actually want to compare a variable loosely to null. That's because Javascript considers Hence why, instead, we should replace all the undefined == null; // `true`
"" == null; // `false` |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rebase (tested here: https://github.com/Faless/godot/tree/temp/86089) and squash, then I think this is good to go.
Great job 👍
95a68e5
to
b484cd5
Compare
b484cd5
to
0b13127
Compare
0b13127
to
62cec03
Compare
Rebase done! |
Thanks! Great feature to have :) |
Sister PR to #85939
When the PWA option is enabled, the installed PWA will make sure to enable COEP/COOP request headers if the option is selected.